/*
 * Copyright (c) 2006-2019, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2019-09-09     RT-Thread    first version
 */

#include <rtthread.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include "dev_api.h"
#include "com.h"

// #define DBG_TAG "main"
// #define DBG_LVL DBG_LOG
// #include <rtdbg.h>
int main(void)
{
  uint8_t cur_sec = 0;
  rtc_time_t rtc_time;
  rtc_get_time(&rtc_time);
  cur_sec = rtc_time.second;
  while (1) {
    iwdg_feed();
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_10);
    if(rt_sem_take(com_dev_sem, RT_WAITING_NO) == RT_EOK) {
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
      com_service();
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
    }
    rtc_get_time(&rtc_time);
    if(cur_sec != rtc_time.second) {
      cur_sec = rtc_time.second;
      HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
    }
    rt_thread_yield();
  }
  return RT_EOK;
}

